// pages/achievement/achievement/achievement.js
import { toast} from '../../../utils/Tools'
import { getAlertCode } from "../../../network/other";
const app = getApp()
Page({
  data: {
    userinfo:{},
    isWarn: true
  },
  onLoad: function (options) {
    this.setData({
      userinfo: wx.getStorageSync('business_user') || app.globalData.business_user
    })
    this._getAlertCode()
  },
  //     函数事件     //
  async _getAlertCode(){
    const res = await getAlertCode()
    if(res.data){
      const result = res.data.some(res=>{
        return res;
      })
      this.setData({
        isWarn: result
      })
    }
  },
  handleOutLogin(e){  //   退出登录
    const {type} = e.currentTarget.dataset
    wx.showModal({
      title: `${type}`,
      content: `是否确认${type}`,
      success: (result) => {
        clearInterval(app.globalData.driverTask)
        if(result.confirm){
          wx.removeStorage({
            key: 'business_user',
            success: res=>{
              wx.removeStorageSync('token')
              toast(`${type}成功`,'success')
              setTimeout(()=>{
                wx.reLaunch({
                  url: '/pages/other/register/register'
                });
              },1000)
            }
          });
        }else{
          toast('取消退出登录')
        }
      }
    });
  }
})